var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var module = angular.module('footer', []);
module.component('footer', {
    transclude: {
        'left': '?left',
        'right': '?right'
    },
    template: `
<div class="footer">
    <ng-transclude ng-transclude-slot="left">
        <input ng-show="!$ctrl.hideLeft" type="button" value="首 页" name="exit" class="exit" voice-control="首页,退出" onclick="javascript:PageForward.toMain();"/>
    </ng-transclude>
    <ng-transclude ng-transclude-slot="right">
    </ng-transclude>
    <div class="timing">剩余操作时间：<span ng-show="$ctrl.countDown">{{$ctrl.countDown}}</span></div>
</div>
    `,
    controller: function ($scope, footerService) {
        if (this.countDown == 0) {
            return;
        }
        var self = this;
        self.$onInit = function () {
            return __awaiter(this, void 0, void 0, function* () {
                while (!self.countDown) { //等待赋值完成
                    yield $sleep(10);
                }
                while (self.countDown > 0) {
                    if (self.destroyed) {
                        return;
                    }
                    yield $sleep(1000);
                    self.countDown--;
                    $scope.$apply();
                }
                PageForward.toMain();
            });
        };
        const hideLeftCallbackId = new Date().getTime();
        self.$onDestroy = function () {
            self.destroyed = true;
            footerService.removeHideLeft(hideLeftCallbackId);
        };
        footerService.onNotifyHideLeft(`${hideLeftCallbackId}`, function () {
            self.hideLeft = true;
        });
    },
    bindings: {
        countDown: '<'
    }
});
module.factory("footerService", function () {
    const hideLeftCallbacks = {};
    const notifyHideLeft = function () {
        for (let funId in hideLeftCallbacks) {
            hideLeftCallbacks[funId]();
        }
    };
    const onNotifyHideLeft = function (hideLeftCallbackId, callback) {
        hideLeftCallbacks[hideLeftCallbackId] = callback;
    };
    const removeHideLeft = function (hideLeftCallbackId) {
        delete hideLeftCallbacks[hideLeftCallbackId];
    };
    return {
        onNotifyHideLeft: onNotifyHideLeft,
        notifyHideLeft: notifyHideLeft,
        removeHideLeft: removeHideLeft
    };
});
